package com.zgkxzx.数据结构.栈;

/**
 * 创建者   zgkxzx
 * 创建日期 2018/4/30.
 * 功能描述
 */
public class ArrayStack<T> implements BaseStack<T> {

    private T t[];
    private int currentIndex = -1;

    private int max = 0;

    public ArrayStack(int size) {
        t = (T[]) new Object[size];
        this.max = size;
    }


    @Override
    public T pop() {
        if (currentIndex == -1)
            return null;
        return t[currentIndex--];
    }

    @Override
    public void push(T t) {
        if (currentIndex < max - 2)
            this.t[++currentIndex] = t;
    }

    @Override
    public T peek() {
        if (currentIndex == -1)
            return null;
        return t[currentIndex];
    }
}
